JsonConvert. SerializeObject () is used to implement json-type object conversion from jsonobject to java object.
Currently, the project uses the idea of frontend and backend separation. Angular. JS is used for the frontend, And the backend uses the ABP framework. In the backend, we use WebAPI technology to provide json data to the frontend. Previously, I used MVC to write front-end code. I felt that the back-end was somewhat at the control of the fron
The JSON data returned is as follows:[[1400025600,9633460,9667535,2698.09,2734.73,2749,2698.08,25333.3057,11784.9,13548.4,69148900],[ 1400112000,9667536,9700700,2734.94,2771.01,2790,2731.48,24260.1011,11824.5,12435.6,67093300],[ 1400198400,9700701,9736706,2771,2789,2816.33,2730,34824.2351,17912.2,16912,96751200],[ 1400284800,9736707,9752556,2789,2782.03,2800,2775,9279.0273,4603.73,4675.29,25840300]]Use: Dynamic Jsonrespot = jsonconvert.deserializeobjectCannot deserialize the current JSON array (
= "SELECT * from Customer"; stringsql =string. Format ("select * FROM {0}", customer); //creates a command object that specifies the SQL statement to execute with the connection object ConnSqlCommand cmd =NewSqlCommand (sql, con); Console.WriteLine ("Open success, status"+con. State); //executing a query returns a result setSqlDataReader SDR =cmd. ExecuteReader (); while(SDR). Read ()) {Customer C=NewCustomer (); C.customerid= sdr["CustomerId"].
Extension method to deserialize a JSON string into a DataTable Type DataTablepublic static DataTable derializetodatatable (this string Str){DataTable dt = new DataTable ();if (str[0] = = ' [')//if The first character of STR is ' [', it means that
:
[DataContract]
Publicclass User
{
Number
[DataMember]
Publicint UserId {get; set;}
User name
[DataMember]
Publicstring UserName {get; set;}
Creation time
[DataMember]
[Jsonconverter (typeof (Isodatetimeconverter))]
Public DateTime createdate {get; set;}
Birthday
[DataMember]
[Jsonconverter (typeof (Javascriptdatetimeconverter))]
Public DateTime Birthday {get; set;}
Related URLs
[DataMember]
Public listSalary
[scriptignore]//This field is not serialized when using Java
:[DataContract]Publicclass User{/// /// No./// [DataMember]Publicint UserId {get; set ;}/// /// User Name/// [DataMember]Publicstring UserName {get; set ;}/// /// Creation Time/// [DataMember][JsonConverter (typeof (IsoDateTimeConverter)]Public DateTime CreateDate {get; set ;}/// /// Birthday/// [DataMember][JsonConverter (typeof (JavaScriptDateTimeConverter)]Public DateTime Birthday {get; set ;}/// /// Related URL/// [DataMember]Public List /// /// Salary/// // [ScriptIgnore] // This field is n
, we have to mention JSON. NET. It is a very famous tool for processing JSON in. net. The most commonly used are the following two features.
1. Convert. net objects to JSON strings through serialization
During web development, we often need to convert the data (generally a collection, list, or array) queried from the database into JSON format strings and send them back to the client, this requires sorting. Here we use the SerializeObject method of the JsonCo
JSON format string back to the client, which needs to be serialized, here is the SerializeObject method of the JsonConvert object. Its syntax is Jsonconvert.serializeobject (object), and "Object" in the code is the. NET object to serialize, and the JSON string is returned after serialization.For example, now we have a tstudent student table, the fields in the table and the existing dataFrom the table we can see a total of five data, now we want to ex
; }Post-Deletion JSONYou can see that count has been removed from the JSON object.5, traversing the JSON objectYou can use for...in ... Loop to iterate through the data in the JSON object, for example, we want to traverse the value of the output obj object, the code is as follows:function traversal () { for (var. c in obj) { Console.log (c + ":", Obj[c]);} }The program output results are:The program output results are:How to use JSON in. NetWhen it comes t
the database (typically a collection, a list or an array, etc.) to a JSON format string back to the client, which needs to be serialized, here is the SerializeObject method of the JsonConvert object. Its syntax is Jsonconvert.serializeobject (object), and "Object" in the code is the. NET object to serialize, and the JSON string is returned after serialization.For example, now we have a tstudent student table, the fields in the table and the existing
, a list or an array, etc.) to a JSON format string back to the client, which needs to be serialized, here is the SerializeObject method of the JsonConvert object. Its syntax is Jsonconvert.serializeobject (object), and "Object" in the code is the. NET object to serialize, and the JSON string is returned after serialization. For example, now we have a tstudent student table, the fields in the table and the existing data From the table we can see a to
ArticleDirectory
Introduction to front-end plug-ins
Background tools
Front-end JSON reading
JSON processing in the background:
Introduction to front-end plug-ins
Jquery. JSON plugin {jquery plugin}
Main Methods:
$. Tojson (JSON object): converts a JSON object to a string.
$. Evaljson (STR): converts a string to a JSON object.
Plug-in download: jquery. json-2.3.min.js
Background tools
Json.net
Main Methods:
Convert an object to a JSON string:
User u =
.5, traversing the JSON objectYou can use for...in ... Loop to iterate through the data in the JSON object, for example, we want to traverse the value of the output obj object, the code is as follows:function traversal () { for (var in obj) { + ": ", Obj[c]) ; } }The program output results are:How to use JSON in. NetWhen it comes to using JSON in. NET, you have to mention Json.NET, which is a very well-known tool for working with JSON in. NET, the foll
datetime time;
Public datetime time{Get {return time ;}Set {time = value ;}}Private double money;
Public double money{Get {return money ;}Set {money = value ;}}Private string [] STR;
Public String [] Str{Get {return STR ;}Set {STR = value ;}}}
Page background functions:
Convert an object to JSON:
User user = new user ();User. ID = 1;User. Name = "you ";User. Money = 2.3;User. Time = datetime. now;User. Str = new string [] {"1", "2", "3 "};Jayrock. JSON. jsontextwriter wri
db. XRole
Where r. RoleId = role. RoleId
Select r;
Foreach (XRole r in q)
{
R. RoleId = role. RoleId;
R. RoleName = role. RoleName;
}
Db. SubmitChanges ();
Return db. XRole. ToList ();
}
}
}
4. ashx code
The Code is as follows:
///
/// Obtain all roles///
Public void GetAllRoles ()
{
StringBuilder jsonData = new StringBuilder ();
Int start = Convert. ToInt32 (Request ["start"]);
Int limit = C
Modify http://www.cnblogs.com/freexiaoyu/archive/2012/08/21/2649333.htmlusage
Or the original JSON format
Model class
View code
Namespace Maticsoft. model { /// /// Return JSON attributes /// [Serializable] Public Class Backinfo { /// /// Status /// Public String result { Get ; Set ;} /// /// Returned data /// Public List Get ; Set ;}} /// /// Return JSON attributes /// [Serializable] Public C
Preparations· Customer classCopy codeThe Code is as follows:Public class Customer{Public int Unid {get; set ;}Public string CustomerName {get; set ;}Public string Memo {get; set ;}Public string Other {get; set ;}} (1) ashxCopy codeThe Code is as follows:Customer customer = new Customer{Unid = 1, CustomerName = "", Memo = "Tian kuixing", Other = "sanlang "};String strJson = Newtonsoft. Json. JsonConvert. SerializeObject (customer );Context. Response. W
db. XRole
Where r. RoleId = role. RoleId
Select r;
Foreach (XRole r in q)
{
R. RoleId = role. RoleId;
R. RoleName = role. RoleName;
}
Db. SubmitChanges ();
Return db. XRole. ToList ();
}
}
}
4. ashx code
The Code is as follows:
///
/// Obtain all roles///
Public void GetAllRoles ()
{
StringBuilder jsonData = new StringBuilder ();
Int start = Convert. ToInt32 (Request ["start"]);
Int limit = C
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.